package com.hjc.service.impl;

import com.hjc.entity.Result;
import com.hjc.entity.Store;
import com.hjc.mapper.StoreMapper;
import com.hjc.page.Page;
import com.hjc.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
@CacheConfig(cacheNames = "com.hjc.service.impl.StoreServiceImpl")
@Service
public class StoreServiceImpl implements StoreService {
    @Autowired
    private StoreMapper storeMapper;

    @Cacheable(key = "'all:store'")
    @Override
    public List<Store> findAllStore() {
        return storeMapper.selectAllStore();
    }

    @Override
    public Result findStoreByPage(Store store, Page page) {
        int storeCount = storeMapper.selectStoreCount(store);
        List<Store> storeList = storeMapper.selectStoreByPage(store, page);

        page.setTotalNum(storeCount);
        page.setResultList(storeList);

        return Result.ok(page);
    }
}
